import Request from '../common/js/request'

// 用户接口
class UserService {
  /**
   * 获取登录用户信息
   */
  static getUserInfo() {
    const url = '/api-upms/user/getUserInfo'

    return Request.get(url)
  }

  /**
   * 根据关键字查询用户手机号、邮箱是否已被注册
   * @param keyword 关键字
   * @param userId 需要忽略的用户Id
   */
  static getIsExistsByKeyword(keyword, userId) {
    const url = '/api-upms/user/getIsExistsByKeyword'

    const data = {
      keyword,
      userId
    }

    return Request.get(url, data)
  }

  /**
   * 获取用户列表
   * @param keyword 关键字
   * @param pageNum 当前页数
   * @param pageSize 每页条数
   */
  static getUserListByKeyword(keyword, pageNum, pageSize) {
    const url = '/api-upms/user/getUserListByKeyword'

    const data = {
      keyword,
      pageNum,
      pageSize
    }

    return Request.get(url, data)
  }

  /**
   * 添加用户
   * @param user 用户表单对象
   */
  static insertUser(user) {
    const url = '/api-upms/user/insertUser'

    user.roleIds = user.roleIds.toString()

    const data = user

    return Request.post(url, data)
  }

  /**
   * 更新用户
   * @param user 用户表单对象
   */
  static updateUser(user) {
    const url = '/api-upms/user/updateUser'

    user.roleIds = user.roleIds.toString()

    const data = user

    return Request.post(url, data)
  }

  /**
   * 删除用户
   * @param userIds 用户Id数组
   */
  static deleteUsers(userIds) {
    const url = '/api-upms/user/deleteUsers'

    const data = {
      userIds: userIds.toString()
    }

    return Request.post(url, data)
  }

  /**
   * 添加用户权限
   * @param userId 用户Id
   * @param permissionIds 权限Id数组
   */
  static insertUserPermission(userId, permissionIds) {
    const url = '/api-upms/user/insertUserPermission'

    const data = {
      userId,
      permissionIds: permissionIds.toString()
    }

    return Request.post(url, data)
  }
}

export default UserService
